package com.finalshell;

import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain;
import java.util.Scanner;

public class Transformer_yo implements ClassFileTransformer {

    @Override
    public byte[] transform(ClassLoader loader, String className,
                            Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer)
            throws IllegalClassFormatException {
        if ("com.yo".equals(className.replace("/", "."))) { // 需要修改的类的全限定名
            try {
                // 获取 ClassPool 实例
                ClassPool classPool = ClassPool.getDefault();
                // 获取指定类的 CtClass 对象
                CtClass ctClass = classPool.get(className.replace("/", "."));
                if(ctClass != null) {
                    System.out.println("" +
                            "\n***************FinalShell_4.2.4.2(注册机)***************\n" +
                            "1.本次发布的内容仅供学习研究使用。\n" +
                            "2.您必须在使用后的24小时之内，从您的电脑中彻底删除上述内容。\n" +
                            "3.访问本内容，说明您已同意上述条款。\n\n" +
                            "********************防止联网验证激活方法********************\n" +
                            "方法一\n" +
                            "需要自建dns添加以下拦截域名\n" +
                            "dkys.org\n" +
                            "youtusoft.com\n" +
                            "hostbuf.com\n" +
                            "tcpspeed.com\n" +
                            "wn1998.com\n" +
                            "\n" +
                            "方法二（推荐）\n" +
                            "使用火绒安全软件,IP黑名单功能,屏蔽IP地址，\n" +
                            "或者windows下使用simplewall(推荐)防火墙软件大小不到2M，自定义规则阻止地址：\n" +
                            "101.32.72.254\n" +
                            "45.56.98.223\n\n" +
                            "********************************************************\n\n" +
                            "QQ群：740641908\n" +
                            "注：如有问题请及时联系群主\n" +
                            "如果您已注册成功，可跳过本注册机启动。\n\n" +
                            "");
                    Scanner scanner = new Scanner(System.in);
                    System.out.println("是否同意？（输入Y继续，其他字符退出）:");
                    String input = scanner.nextLine();
                    if (input.equalsIgnoreCase("Y")) {
                        System.out.println("您已同意上述条款!!!\n" +
                                "将为您显示本机激活码：");
                    } else {
                        System.out.println("已取消显示本机激活码,将为您正常启动程序。");
                        // 在这里添加需要执行的代码
                        scanner.close();
                        return ctClass.toBytecode();
                    }
                    scanner.close();
                }

                // 需要修改的方法名
                CtMethod ctMethod = ctClass.getDeclaredMethod("a");
                if(ctMethod != null){
                    // 重写方法体
                    ctMethod.setBody("{" +
                            "      System.out.println(\"机器码：\" + (String)com.Kh.X.iterator().next());\n" +
                            "      //String var0 = cz.e(\"eVoFGFF5UjgAdD1SHkEwARk2HDQkIvJsI6FikyafAk8NEzr+\");\n" +
                            "      //System.out.println(\"机器码1：\" + var0);\n" +
                            "      fm var1 = new fm();\n" +
                            "      String var2;\n" +
                            "      try {\n" +
                            "         var2 = fn.b(var1.a(((String)com.Kh.X.iterator().next() + \"hSf(78cvVlS5E\").getBytes(\"UTF-8\"), bb.KECCAK_384)).subSequence(12, 28).toString();\n" +
                            "         ar.add(var2);\n" +
                            "         System.out.println(var1.a(\"caolei152634@cc6446b52c287153hSf(78cvVlS5E\".getBytes(\"UTF-8\"), bb.KECCAK_384));\n" +
                            "         System.out.println(\"高级版：\" + var2);\n" +
                            "      } catch (Exception var4) {\n" +
                            "         var4.printStackTrace();\n" +
                            "      }\n" +
                            "      //var0 = cz.e(\"D2NgUVJGXB5zOm99HyNVXD1hTB41Yne1A0N5KyuxC+c0LI6P\");\n" +
                            "      //System.out.println(\"机器码2：\" + var0);\n" +
                            "      try {\n" +
                            "         var2 = fn.b(var1.a(((String)com.Kh.X.iterator().next() + \"FF3Go(*Xvbb5s2\").getBytes(\"UTF-8\"), bb.KECCAK_384)).subSequence(12, 28).toString();\n" +
                            "         aq.add(var2);\n" +
                            "         System.out.println(\"专业版：\" + var2);\n" +
                            "      } catch (Exception var3) {\n" +
                            "         var3.printStackTrace();\n" +
                            "      }\n" +
                            "      //System.out.println(bb.KECCAK_384.a());\n" +
                            "      //System.out.println(bb.KECCAK_384.b());\n" +
                            "      //System.out.println(bb.KECCAK_384.c());\n" +
                            "   }");
                    // 返回修改后的字节码数组
                    return ctClass.toBytecode();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
/**
 *bb.KECCAK_384.a()=832
 * bb.KECCAK_384.b()=1
 * bb.KECCAK_384.c()=384
 **/